import { Component, EventEmitter, Input, Output } from '@angular/core';
import { EditState } from '../../core';

@Component({
  // eslint-disable-next-line @angular-eslint/component-selector
  selector: 'j:ebuttons',
  templateUrl: './entity-form-buttons.component.html',
  styleUrls: ['./entity-form-buttons.component.less'],
})
export class EntityFormButtonsComponent {
  //编辑状态
  @Input()
  editState: EditState = EditState.Empty;

  //按钮是否显示
  @Input()
  saveBtnVisible: boolean = true;
  @Input()
  giveupBtnVisible: boolean = true;
  @Input()
  newBtnVisible: boolean = true;
  @Input()
  copyBtnVisible: boolean = true;
  @Input()
  deleteBtnVisible: boolean = true;
  @Input()
  operateDividerVisible: boolean = true;
  @Input()
  submitBtnVisible: boolean = true;
  @Input()
  backBtnVisible: boolean = true;
  @Input()
  approveBtnVisible: boolean = true;
  @Input()
  unapproveBtnVisible: boolean = true;
  @Input()
  approveDividerVisible: boolean = true;
  @Input()
  selectBtnVisible: boolean = true;
  @Input()
  listBtnVisible: boolean = true;
  @Input()
  searchDividerVisible: boolean = true;
  @Input()
  printBtnVisible: boolean = true;
  @Input()
  refreshBtnVisible: boolean = true;

  //按钮是否可用处理方法
  @Input()
  saveBtnDisabledFn: () => boolean = () =>
    this.editState == EditState.Empty ||
    this.editState == EditState.View ||
    this.editState == EditState.Appoving ||
    this.editState == EditState.Appoved;
  @Input()
  giveupBtnDisabledFn: () => boolean = () =>
    this.editState == EditState.Empty ||
    this.editState == EditState.View ||
    this.editState == EditState.Appoving ||
    this.editState == EditState.Appoved;
  @Input()
  newBtnDisabledFn: () => boolean = () => false;
  @Input()
  copyBtnDisabledFn: () => boolean = () =>
    this.editState == EditState.Empty || this.editState == EditState.Creating;
  @Input()
  deleteBtnDisabledFn: () => boolean = () =>
    this.editState == EditState.Empty ||
    this.editState == EditState.Creating ||
    this.editState == EditState.Appoving ||
    this.editState == EditState.Appoved;
  @Input()
  submitBtnDisabledFn: () => boolean = () =>
    this.editState == EditState.Empty ||
    this.editState == EditState.Creating ||
    this.editState == EditState.Editing ||
    this.editState == EditState.Appoving ||
    this.editState == EditState.Appoved;
  @Input()
  backBtnDisabledFn: () => boolean = () =>
    this.editState == EditState.Empty ||
    this.editState == EditState.Creating ||
    this.editState == EditState.View ||
    this.editState == EditState.Editing ||
    this.editState == EditState.Appoved;
  @Input()
  approveBtnDisabledFn: () => boolean = () =>
    this.editState == EditState.Empty ||
    this.editState == EditState.Creating ||
    this.editState == EditState.View ||
    this.editState == EditState.Editing ||
    this.editState == EditState.Appoved;
  @Input()
  unapproveBtnDisabledFn: () => boolean = () =>
    this.editState == EditState.Empty ||
    this.editState == EditState.Creating ||
    this.editState == EditState.View ||
    this.editState == EditState.Editing ||
    this.editState == EditState.Appoving;
  @Input()
  selectBtnDisabledFn: () => boolean = () => false;
  @Input()
  listBtnDisabledFn: () => boolean = () => false;
  @Input()
  printBtnDisabledFn: () => boolean = () =>
    this.editState == EditState.Empty ||
    this.editState == EditState.Creating ||
    this.editState == EditState.Appoving ||
    this.editState == EditState.Appoved;
  @Input()
  refreshBtnDisabledFn: () => boolean = () => false;

  //按钮是否可用属性
  get saveBtnDisabled() {
    return this.saveBtnDisabledFn();
  }
  get giveupBtnDisabled() {
    return this.giveupBtnDisabledFn();
  }
  get newBtnDisabled() {
    return this.newBtnDisabledFn();
  }
  get copyBtnDisabled() {
    return this.copyBtnDisabledFn();
  }
  get deleteBtnDisabled() {
    return this.deleteBtnDisabledFn();
  }
  get submitBtnDisabled() {
    return this.submitBtnDisabledFn();
  }
  get backBtnDisabled() {
    return this.backBtnDisabledFn();
  }
  get approveBtnDisabled() {
    return this.approveBtnDisabledFn();
  }
  get unapproveBtnDisabled() {
    return this.unapproveBtnDisabledFn();
  }
  get selectBtnDisabled() {
    return this.selectBtnDisabledFn();
  }
  get listBtnDisabled() {
    return this.listBtnDisabledFn();
  }
  get printBtnDisabled() {
    return this.printBtnDisabledFn();
  }
  get refreshBtnDisabled() {
    return this.refreshBtnDisabledFn();
  }

  //按钮点击事件
  @Output() readonly saveBtnClick = new EventEmitter();
  @Output() readonly giveupBtnClick = new EventEmitter();
  @Output() readonly newBtnClick = new EventEmitter();
  @Output() readonly copyBtnClick = new EventEmitter();
  @Output() readonly deleteBtnClick = new EventEmitter();
  @Output() readonly submitBtnClick = new EventEmitter();
  @Output() readonly backBtnClick = new EventEmitter();
  @Output() readonly approveBtnClick = new EventEmitter();
  @Output() readonly unapproveBtnClick = new EventEmitter();
  @Output() readonly selectBtnClick = new EventEmitter();
  @Output() readonly listBtnClick = new EventEmitter();
  @Output() readonly printBtnClick = new EventEmitter();
  @Output() readonly refreshBtnClick = new EventEmitter();

  OnSaveBtnClick() {
    this.saveBtnClick.emit();
  }
  OnGiveupBtnClick() {
    this.giveupBtnClick.emit();
  }
  OnNewBtnClick() {
    this.newBtnClick.emit();
  }
  OnCopyBtnClick() {
    this.copyBtnClick.emit();
  }
  OnDeleteBtnClick() {
    this.deleteBtnClick.emit();
  }
  OnSubmitBtnClick() {
    this.submitBtnClick.emit();
  }
  OnBackBtnClick() {
    this.backBtnClick.emit();
  }
  OnApproveBtnClick() {
    this.approveBtnClick.emit();
  }
  OnUnapproveBtnClick() {
    this.unapproveBtnClick.emit();
  }
  OnSelectBtnClick() {
    this.selectBtnClick.emit();
  }
  OnListBtnClick() {
    this.listBtnClick.emit();
  }
  OnPrintBtnClick() {
    this.printBtnClick.emit();
  }
  OnRefreshBtnClick() {
    this.refreshBtnClick.emit();
  }

  @Output() readonly searchBtnClick = new EventEmitter();
  code: string;
  OnSearchBtnClick() {
    this.searchBtnClick.emit(this.code);
    this.code = undefined;
  }

  @Input()
  searchPlaceholder: string = '';
}
